<?php

if (isset($this->ref)) {
    if (isset($this->record)) {
        $tagsModel = new TagsModel();
        foreach ($this->fields as $f) {
            $field = $f->field;
            if ($f->type == "tags") {
                $tags = $tagsModel->getObjectTags($f->identifier, $this->record->id);
                $i = 0;
                $this->record->$field = '';
                foreach ($tags as $k => $t) {
                    if ($i > 0) {
                        $this->record->$field .= ', <a href="' . $this->page->url . '/tag/' . $k . '">' . $t . '</a>';
                    } else {
                        $this->record->$field .= '<a href="' . $this->page->url . '/tag/' . $k . '">' . $t . '</a>';
                    }
                    $i++;
                }
            }
            echo '<p>' . $f->title . ': ' . $this->record->$field . '</p>';
        }
    } else {
        echo '<h1>' . $this->ref['title'] . '</h1>';
        if (isset($this->tag)) {
            echo '<h2>' . $this->t->_('By tag'). ' "'.$this->tag->tag.'"</h2>';
        }
        echo '<table class=ref_table><thead><tr>';
        foreach ($this->fields as $f) {
            if ($f->type <> "tags")
                if ($f->visible > 0)
                    echo '<th>' . $f->title . '</th>';
        }
        echo '</tr></thead>';
        foreach ($this->records as $r) {
            echo '<tr>';
            foreach ($this->fields as $f) {
                $field = $f->field;
                if ($f->type <> "tags")
                    if ($f->visible)
                        echo '<td><a href="' . PAGE_URL . '/' . $this->ref['param'] . '/' . $r->id . '">' . $r->$field . '</td>';
            }
            echo '</tr>';
        }
        echo '</table>';
        echo $this->partial('paginator.phtml', array('paginator' => $this->records->getPages(), 't' => $this->t));
    }
}
?>

